<?php
/**
 * Created by dzw.
 * User: Administrator
 * Date: 2018-03-16
 * Time: 10:22
 */

namespace App\Http\Controllers\Admin\Report;

use App\Http\Controllers\Admin\BaseController;
use Illuminate\Http\Request;

class ReportController extends BaseController
{
    protected $api_url = [
        'get' => ['get', 'report'],//获取列表
        'status' => ['put', 'report'],//更改状态
    ];

    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_backend');
    }

    public function indexAction()
    {
        //参数部分
        $search_params = $this->request->all(['user_name', 'shop_name','product_name','create_at','status']);
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'page' => $page,
            'orderBy'=>'id',
            'sortedBy'=>'desc',
        ];

        //请求部分
        $ret = http_admin($this->api_url['get'])->send($params);

        //结果处理部分
        $this->httpCodeJudge($ret);
        $data = paginate($this->request, $ret['data']);

        //回填搜索框值
        $data['search_params'] = $search_params;

        return view('Admin.report.list', $data);
    }

    public function updateAction()
    {
        $params = $this->request->all(['id','state']);

        $updateparams['id'] =$params['id'];
        $updateparams['status'] =$params['state'];

        $ret = http_admin($this->api_url['status'])->send($updateparams);

        //结果处理
        $this->httpCodeJudge($ret);

        return $ret;
    }


}